package Task16;

import java.util.Scanner;

/**
 * 比较两手扑克牌大小
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextLine()) {
            String str = in.nextLine();
            String[] str1 = str.split("-");
            String[] str2 = str1[0].split(" ");
            String[] str3 = str1[1].split(" ");
            String str4 = "34567891JQKA2";
            if(str1[0].equals("joker JOKER") || str1[1].equals("joker JOKER")){
                System.out.println("joker JOKER");
            }else if(str2.length == str3.length){
                if(str4.indexOf(str2[0].substring(0,1)) > str4.indexOf(str3[0].substring(0,1))){
                    System.out.println(str1[0]);
                }else{
                    System.out.println(str1[1]);
                }
            }else if(str2.length == 4){
                System.out.println(str1[0]);
            }else if(str3.length == 4){
                System.out.println(str1[1]);
            }else{
                System.out.println("ERROR");
            }
        }
    }
}
